#include <event.h>
/* BEGIN OF CONSTANT */
// Server consts
#define SERVER_ADDR					"0.0.0.0"
#define SERVER_PORT					10086
#define MAX_CLIENT					65536
#define MAX_SEND_TIME				10
#define BUFFER_SIZE					4096
#define CMD_LENGTH					255
#define ADMIN_IP					"127.0.0.1"

#define QUEUE_TABLE_SIZE			65536
#define EVENT_TABLE_SIZE			32768
#define EVENT_ID_ALIGN				10000

#define MIN_EVENT_TIME 60 

#ifndef MAX_GROUP
#define MAX_GROUP	10
#endif

#define MAX_BUF 5000
/* END OF CONSTANT */

struct queue_item
{
	int item_id;
	time_t end_time;
};

struct queue_table
{
	struct queue_item table[QUEUE_TABLE_SIZE];
	struct queue_table * next;
};

struct event_item
{
	time_t start_time;
	int loop;
	int interval;
	unsigned char cmd[CMD_LENGTH];
};

struct event_table
{
	struct event_item table[EVENT_TABLE_SIZE];
	struct event_table * next;
};

/* BEGIN OF STRUCT DEFINE */
// Player
struct conn_client
{
	// Socket informations
	unsigned int id;
	int client_fd;
	char *ipv4_addr;
	char *ipv6_addr;
	struct bufferevent *buffer_event;
	unsigned int conn_time;
};
/* END OF STRUCT DEFINE */

/* BEGIN OF FUNCTION DEFINE */
void conn_accept						(int, short, void *);
int conn_daemonize						();
void conn_free							(struct conn_client *);
struct conn_client * conn_from_list		();
int conn_init							(int);
void conn_on_error						(struct bufferevent *, short, void *);
void conn_on_read						(struct bufferevent *, void *);
void conn_on_write						(struct bufferevent *, void *);
int conn_send							(struct conn_client *, unsigned char *);
int conn_setnonblock					(int);
/* END OF FUNCTION DEFINE */

void *					loop_queue_table(void *);

int						queue_table_init();
struct queue_table *	queue_table_add(int);
int						queue_item_add(int, time_t, int);

int						event_table_init();
struct event_table *	event_table_add();
int						event_item_add(int, int, unsigned char *);
int						event_item_delete(int);
struct event_item *		event_item_find(int);
int touchcache(const char *);
int purgedir(const char*,const char*);

#include "expat.h"

static void XMLCALL startElement (void *,const char*,const char **);
static void XMLCALL endElement(void *,const char*);
static void chardatahandle(void *,const char*,int);
void parxml();
int purgeurl(char *,char *);

#ifdef XML_LARGE_SIZE
#if defined(XML_USE_MSC_EXTENSIONS) && _MSC_VER < 1400
#define XML_FMT_INT_MOD "I64"
#else
#define XML_FMT_INT_MOD "ll"
#endif
#else
#define XML_FMT_INT_MOD "l"
#endif

